Thread: Accessing and writing to a vector [Beginner]

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    3

    Accessing and writing to a vector [Beginner]

    for (int k = 0; j < students.size() ; j++)
    {
    studentdetails student = students[j];
    student.print();
    }
    Last edited by w00ty; 05-14-2011 at 04:35 PM. Reason: output was too long

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
    studentdetails student = students[j];
    creates a brand new student. Thus the student in your vector is ignored.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    3
    Thanks for the quick reply tabstop

    Quote Originally Posted by tabstop View Post
    Code:
    studentdetails student = students[j];
    creates a brand new student. Thus the student in your vector is ignored.
    Sorry to ask but Any hints on how to load that data into the correct vector . tried assign and referencing it but not getting anywhere
    Last edited by w00ty; 05-14-2011 at 02:35 PM.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by w00ty View Post
    Thanks for the quick reply tabstop



    Sorry to ask but Any hints on how to load that data into the correct vector . tried assign and referencing it but not getting anywhere
    If you've done anything other than remove that line, then you're not thinking. You want to use the element of the vector. That's the point of the vector, is to have these elements around that we are modifying.

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    3
    Quote Originally Posted by tabstop View Post
    If you've done anything other than remove that line, then you're not thinking. You want to use the element of the vector. That's the point of the vector, is to have these elements around that we are modifying.
    Fixed it and thanks, Actually kinda angry at myself for not noticing what my mistake was

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vector : accessing values
    By rahulsk1947 in forum C++ Programming
    Replies: 1
    Last Post: 06-01-2009, 09:26 PM
  2. Accessing Member Methods inside a Vector
    By xmltorrent in forum C++ Programming
    Replies: 5
    Last Post: 06-23-2008, 12:02 PM
  3. vector accessing
    By Snip in forum C++ Programming
    Replies: 4
    Last Post: 02-08-2006, 05:03 PM
  4. Help with accessing vector variables
    By earth_angel in forum C++ Programming
    Replies: 12
    Last Post: 06-28-2005, 09:48 AM
  5. Accessing vector pointers
    By blue8173 in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2003, 07:32 PM